package com.pandora.templating;

import java.util.Vector;

import com.pandora.model.BlockGroup;
import com.pandora.model.BuildingBlock;
import com.pandora.model.ParameterTable;

public class BlockGroupTemplate extends BuildingBlockTemplate<BlockGroup> {
	
	private Vector<BuildingBlockTemplate<? extends BuildingBlock>> buildingBlockTemplates;	
	
	public BlockGroupTemplate(String name) {
		this(name,null);
	}
	
	public BlockGroupTemplate(String name, String description) {
		super(name,description);
		this.buildingBlockTemplates = new Vector<BuildingBlockTemplate<? extends BuildingBlock>>();
	}
	
	public Vector<BuildingBlockTemplate<? extends BuildingBlock>> getBuildingBlocks() {
		return buildingBlockTemplates;
	}

	public void setBuildingBlocks(Vector<BuildingBlockTemplate<? extends BuildingBlock>> buildingBlocks) {
		this.buildingBlockTemplates = buildingBlocks;
	}
	
	protected BlockGroup createInstance() {
		BlockGroup blockGroup = new BlockGroup(this.name, this.description);
		ParameterTable<?> inParams = this.inParameters.getInstance();
		blockGroup.setInParameters(inParams);
		ParameterTable<?> outParams = this.outParameters.getInstance();
		blockGroup.setOutParameters(outParams);
		Vector<BuildingBlock> subBlocks = new Vector<BuildingBlock>();
		for (BuildingBlockTemplate<?> subBlock : buildingBlockTemplates) {
			MultipleParameterTemplate multi = subBlock.getMultipleParameterTemplate();
			if (multi != null) {
				//TODO
			}
			subBlocks.add(subBlock.getInstance());
		}
		blockGroup.setSubBlocks(subBlocks);
		Vector<BuildingBlock> dependencies = new Vector<BuildingBlock>();
		Vector<BuildingBlockTemplate<? extends BuildingBlock>> dependTemplates = this.getDependencies();
		for (BuildingBlockTemplate<?> dependTemplate : dependTemplates) {
			BuildingBlock depend = dependTemplate.getInstance();
			dependencies.add(depend);
		}
		blockGroup.setDependencies(dependencies);
		return blockGroup;
	}

}
